<?php
/*
 * @Author: DIYGWCOM 
 * @Date: 2018-07-21 23:20:49 
 * @qq: 287598666 
 * @Last Modified by: DIYGWCOM
 * @Last Modified time: 2018-07-26 00:41:14
 */

defined('IN_IA') or exit('Access Denied');

session_start();

require_once('define.php');
require_once('model.php');
require_once('DiygwcomUtil.class.php');
class diygwcom_appModuleSite extends WeModuleSite {


    public function getMenus()
    {
        global $_W;
        return array(
            array('title' => '管理后台', 'icon' => 'fa fa-shopping-cart', 'url' => webUrl())
        );
    }

    function __call($name,$arguments)
    {
        global $_GPC;
        global $_W;
        $isWeb = stripos($name, 'doWeb') === 0;
        $isMobile = stripos($name, 'doMobile') === 0;
        $this->modulename = MODULE_NAME;
        if(isset($_GPC['r'])){
            $r = str_replace('//', '/', trim($_GPC['r'], '/'));
        }else{
            if($isWeb){
                $r = strtolower(substr($name, 5));
                $_GPC['do'] ='web';
            }else if($isMobile){
                $r = strtolower(substr($name, 8));
                $_GPC['do'] ='mobile';
            }
        }
        $routes = explode('_', $r);
        $segs = count($routes);
        if($segs==1){
            $_W['routes'] = $r.'/index';
        }else{
            $_W['routes']= $routes[0].'/'.$routes[1];
        }


        $dir = IA_ROOT . '/addons/' . $this->modulename . '/inc/';
        require_once $dir .'DiygwcomAction.php';
        if($isWeb) {
            $dir .= 'web/';
        }

        if($isMobile) {
            $dir .= 'mobile/';
            require_once $dir .'Interceptor.php';
        }

        $controller = $dir. ucfirst($routes[0]) . '.php';
        if (!(is_file($controller))) {
            exit(' 控制器 ' . $name . ' Not Found!');
        }

        require_once $controller;
        $class_name = ucfirst($routes[0])."_Diygwcom";
        $instance = new $class_name();
        $_modules[$isWeb?"web":"mobile".$name] = $instance;
        $method = 'index';
        if($segs==2){
            $method=$routes[1];
        }
        if (!(method_exists($instance, $method))) {
            message('控制器 ' . $_W['controller'] . ' 方法 ' . $method . ' 未找到!','','error');
        }
        $instance->$method();
        exit();
    }

    public function doWebIndex()
    {
        $this->__call('doWeb');
    }

    public function doMobileIndex()
    {
        $this->__call('doMobile');
    }

    public function payResult($params)
    {
        $dir = IA_ROOT . '/addons/' . $this->modulename . '/inc/';
        require_once $dir .'DiygwcomAction.php';
        $controller = IA_ROOT . '/addons/' . MODULE_NAME . '/inc/mobile/Pay.php';
        require_once $controller;
        $class_name = "Pay_Diygwcom";
        $method="payResult";
        $instance = new $class_name();
        include $instance->$method($params);
        echo 1;
    }
}
